package org.example.hadoop.service.authorFrequency;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: wwy
 * @Date: 2020/11/10 10:21
 */
public class AuthorFrequencyMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
    private static final IntWritable valueInfo = new IntWritable(1);
    private static Text keyInfo = new Text();
    /**
     * k1        v1
     *           https://book.douban.com/subject/4913064/ 活着 小说 余华 9.4 531574 20.00元 作家出版社 2012-8-1 132697
     *
     * k2        v2
     * 余华       1,1,1,1
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] lineArray = line.split(" ");
        String author = lineArray[3];
        keyInfo.set(author);
        context.write(keyInfo,valueInfo);
    }
}
